package com.xingkeduo.pojo.handler;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/6/27 15:42
 **/
@Component
@Aspect
@Slf4j
public class Advice {

    @Pointcut("execution(public * com.xingkeduo.business.user.controller.*.*(..))")
    public void pointcut() {
        // 仅用于定义 Pointcut
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        String classPath = joinPoint.getSignature().getDeclaringTypeName();
        log.info("请求的模板[{}]---------请求方法为:[{}]-----请求参数为:[{}]", classPath.split("\\.")[classPath.split("\\.").length - 1], joinPoint.getSignature().getName(), JSON.toJSONString(joinPoint.getArgs()));
        Object rvt = joinPoint.proceed();
        if (rvt != null && rvt instanceof Integer) {
            rvt = (Integer) rvt * (Integer) rvt;
        }
        long end = System.currentTimeMillis();
        log.info("getMethodTime[{}]", end - start);
        return rvt;
    }

}
